using System;
using System.Collections.Generic;
using System.Text;
using System.Net.NetworkInformation;
using System.Net;
using System.Runtime.InteropServices;
namespace Test {
	class Sql21 {
		static void MainX() {
			//MAL sql=new MAL();
			//sql.NonQry("truncate table user");
			string[] addresses=Mixer.CombineEx("172.26.{0}.{1}","75-76","1-254");
			foreach(string address in addresses)
			{
				PingReply pr=new Ping().Send(address,100);
				if(pr.Status==IPStatus.Success)
				{

					
					IPHostEntry ent=Dns.GetHostEntry(address);

					if(address==ent.HostName)
					{
						//sql.NonQry("insert into user(ip)values('{0}')",address);
					}
					else
					{
						Console.WriteLine(address+"-"+ent.HostName);
						Users.ListUsers(ent.HostName);
						//sql.NonQry("insert into user(machine,ip)values('{0}','{1}')",ent.HostName.Replace(".next-uk.next.loc",""),address);
					}
				}
			}


		}

		static void MainX2() {
			//bool arp0=IsComputerAlive(IPAddress.Parse("125.26.76.52"));

			foreach(string server in Mixer.CombineEx("pon-wpsq21-cl{0:00}","1-8"))
				try
				{
					//IPHostEntry ent=Dns.GetHostEntry(server);
					//bool arp=IsComputerAlive(ent.AddressList[0]);
					Console.Write(server+" - ");
					PingReply pr=new Ping().Send(server,100);
					Console.WriteLine(pr.Status+" "+pr.RoundtripTime);
				}
				catch(Exception ex) { Console.WriteLine(ex.InnerException.Message); }
		}
		static void MainXx() {
			List<string> servers=new List<string>();
			servers.AddRange(Mixer.CombineEx("pon-wpsq21-db{0:00}\\in{0:00}","1-12"));
			servers.AddRange(Mixer.CombineEx("pon-wpsq{0:00}-db","6,8,12,13,16"));
			foreach(string server in servers)
				try
				{
					object o=new DAL(server,"master").Scalar("select getdate()");
					Console.WriteLine(server+" - "+o);
				}
				catch(Exception ex) { Console.WriteLine(server+":"+ex.Message); }
		}
		//[DllImport("iphlpapi.dll",ExactSpelling=true)]
		//public static extern int SendARP(int DestIP,int SrcIP,byte[] pMacAddr,ref uint PhyAddrLen);
		//static bool IsComputerAlive(IPAddress host) {
		//  //can't check the own machine (assume it's alive)
		//  if(host.Equals(IPAddress.Loopback))
		//    return true;
		//  //Prepare the magic
		//  //this is only needed to pass a valid parameter
		//  byte[] macAddr=new byte[6];
		//  uint macAddrLen=(uint)macAddr.Length;
		//  //Let's check if it is alive by sending an arp request
		//  int res=SendARP((int)host.Address,(int)IPAddress.Parse("127.0.0.1").Address,macAddr,ref macAddrLen);
		//  string mac=BitConverter.ToString(macAddr,0,(int)macAddrLen);
		//  if(res==0)
		//    return true; //Igor it's alive!
		//  return false;//Not alive
		//}
	}
}
